<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${initParam.root }/jquery-1.8.3.js"></script>
<script type="text/javascript">
	$(function(){
		var fname = "${requestScope.map.r_img_new}";
		var img_format="\.(bmp|gif|jpg|jpeg|png)$";
		
		if($(window.opener.document).find("#pForm_4 :hidden[name=command]").val()=="writeDescNext"){
			$("#tempImg").attr("src","${initParam.root }/img/main/main-write-img2.jpg");
		}
		
		if("${requestScope.map}"!=""){
			$("#tempImg").attr("src","${initParam.root }/upload/temp/"+fname);
			$("#fileName").val("${requestScope.map.fileName}");
		
		}
		$("#r_uploadFile").change(function(){
			if((new RegExp(img_format,"i")).test(document.popupForm.r_uploadFile.value)){
				$("#popupForm").submit();
				
			}else{
				alert("지원하지 않는 형식의 파일입니다.");
				return;
			}
			
		
		});
		$("#canclePop").click(function(){
			self.close();
		});
		$("#closePop").click(function(){
			if($("#fileName").val()==""){
				alert("사진을 등록하세요!");
				return;
			}
			
			var imgObj = opener.document.all("r_uploadFile");
			imgObj.src = "${initParam.root }/upload/temp/"+fname;
			opener.document.all("r_img_origin").value = "${requestScope.map.r_img_origin}";
			opener.document.all("r_img_new").value = "${requestScope.map.r_img_new}";
			opener.document.all("r_img_thum").value = "${requestScope.map.r_img_thum}";
			self.close();
		});
	});
</script>
<style type="text/css">
	.file_input_textbox{
		float: left;
		position: relative;
		left:170px;
	}
	.file_input_div{
		position: relative;
		width: 100px;
		height: 23px;
		left:170px;
		overflow: hidden;
	}
	.file_input_button{
		width: 100px;
		position: absolute;
		top: 0px;
		background-color: #f36523;
		color: #FFFFFF;
		border-style: solid;
	}
	.file_button{
		width: 100px;
		background-color: #f36523;

		color: #FFFFFF;
		border-style: solid;
	}
	.file_button{
		width: 100px;
		background-color: #f36523;
		color: #FFFFFF;
		border-style: solid;
		cursor:pointer;
	}
	.file_input_hidden{
		font-size: 45px;
		cursor: pointer;
		position: absolute;
		right: 0px;
		top: 0px;
		opacity: 0;
		filter: alpha(opacity=0);
		-ms-filter: "alpha(opacity=0)";
		-khtml-opacity: 0;
		-moz-opacity: 0;
	}
</style>
</head>
<body>
<form name="popupForm" id="popupForm" method="post" enctype="multipart/form-data" action="${initParam.root }/recipe.do?command=tempFileUpload">
	<div id="divFile" style="width: 400px">
		<input type="text"  id="fileName" class="file_input_textbox" readonly="readonly">
		<div class="file_input_div">
			<input type="button" value="사진 등록" class="file_input_button">
			<input type="file" id="r_uploadFile" name="r_uploadFile" title="사진 등록" class="file_input_hidden">
		</div>
	</div>
	<div id="imgArea" align="center" style="width: 550px; height: 360px; margin: 10px;">
		<img src="${initParam.root }/img/main/main-write-img.jpg" alt="클릭하세요" id="tempImg" style="margin: 5px;">
	</div>
	<div align="center">
		<input type="button" id="closePop" value="결정" class="file_button">
		<input type="button" id="canclePop" value="취소" class="file_button">
	</div>
</form>
</body>
</html>